package neusoft.example.com.yuejian06.Model;

import neusoft.example.com.yuejian06.Bean.Clubvideo;
import neusoft.example.com.yuejian06.PublicIp;
import neusoft.example.com.yuejian06.RetrofitListener;
import neusoft.example.com.yuejian06.Service.ClubService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ClubvideoDetailModel {
    private Retrofit retrofit;
    private ClubService service;
    public ClubvideoDetailModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(PublicIp.ip+"api/club_video/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        service=retrofit.create(ClubService.class);
    }

    public void getClubvideoById(String clubvideo_id, final RetrofitListener<Clubvideo> listener){
        Call<Clubvideo> call=service.getClubvideoById(clubvideo_id);
        call.enqueue(new Callback<Clubvideo>() {
            @Override
            public void onResponse(Call<Clubvideo> call, Response<Clubvideo> response) {
                if(response.isSuccessful()&&response!=null){
                    listener.onResponse(response.body());
                }else {
                    listener.onFail("服务器炸了！");
                }
            }

            @Override
            public void onFailure(Call<Clubvideo> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
